From 8ecd3f241343a53753eb17fd6e060ad673329d12 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 22 Oct 2002 19:11:04 +0000 Subject: [PATCH] Bring in magellan route parsing code I'd had laying around. It's not hooked up to anything useful just yet. --- gpsbabel/Makefile | 2 +- gpsbabel/defs.h | 8 ++++ gpsbabel/gpx.c | 2 +- gpsbabel/magproto.c | 100 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/gpsbabel/Makefile b/gpsbabel/Makefile index 5ed8c99fb..b83592c6b 100644 --- a/gpsbabel/Makefile +++ b/gpsbabel/Makefile @@ -1,4 +1,4 @@ -CFLAGS=-g -Icoldsync -belf -I/usr/local/include/ +CFLAGS=-g -Icoldsync FMTS=magproto.o gpx.o geo.o gpsman.o mapsend.o mapsource.o \ gpsutil.o tiger.o pcx.o csv.o cetus.o gpspilot.o magnav.o \ diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index b33ac3ff7..da0c4f244 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -118,6 +118,14 @@ typedef struct { geocache_data gc_data; } waypoint; +typedef struct { + queue Q; /* Link onto parent list. */ + queue waypoint_list; /* List of child waypoints */ + char *rte_name; + char *rte_desc; + int rte_num; +} route_head; + typedef void (*ff_init) (char const *); typedef void (*ff_deinit) (void); typedef void (*ff_read) (void); diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 4e3b8cf93..87338f63c 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -181,7 +181,7 @@ gpx_end(void *data, const char *el) in_wpt--; } else if (strcmp(el, "rtept") == 0) { - route_add(wpt_tmp); +/* route_add(wpt_tmp); */ in_rte--; } else if (strcmp(el, "name") == 0) { in_name--; diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 3c88c3f4b..4959d0050 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -47,6 +47,22 @@ typedef enum { mrs_handon } mag_rxstate; +/* + * An individual element of a route. + */ +typedef struct mag_rte_elem { + queue Q; /* My link pointers */ + char *wpt_name; + char *wpt_icon; +} mag_rte_elem; + +/* + * A header of a route. Related elements of a route belong to this. + */ +typedef struct mag_rte_head { + queue Q; /* Queue head for child rte_elems */ + int nelems; +} mag_rte_head; static FILE *magfile_in; static FILE *magfile_out; @@ -675,7 +691,91 @@ mag_trkparse(char *trkmsg) } +/* + * Given an incoming route messages of the form: + * $PMGNRTE,4,1,c,1,DAD,a,Anna,a*61 + * generate a route. + */ +waypoint * +mag_rteparse(char *rtemsg) +{ + char descr[100]; + int n; + int frags,frag,rtenum; + char xbuf[100],next_stop[100],abuf[100]; + char *currtemsg; + static mag_rte_head *mag_rte_head; + mag_rte_elem *rte_elem; + + descr[0] = 0; + + sscanf(rtemsg,"$PMGNRTE,%d,%d,%c,%d%n", + &frags,&frag,xbuf,&rtenum,&n); + + /* + * This is the first component of a route. Allocate a new + * queue head. It's kind of unfortunate that we can't know + * a priori how many items are on this track, so we have to + * alloc and chain those as we go. + */ + if (frag == 1) { + mag_rte_head = xmalloc(sizeof (*mag_rte_head)); + QUEUE_INIT(&mag_rte_head->Q); + mag_rte_head->nelems = frags; + } + + currtemsg = rtemsg + n; + /* + * The individual line may contain several route elements. + * loop and pick those up. + */ + while (sscanf(currtemsg,",%[^,],%[^,]%n",next_stop, abuf,&n)) { + if (next_stop[0] == 0) { + break; + } + rte_elem = xmalloc(sizeof (*rte_elem)); + QUEUE_INIT(&rte_elem->Q); + rte_elem->wpt_name = xstrdup(next_stop); + rte_elem->wpt_icon = xstrdup(abuf); + ENQUEUE_TAIL(&mag_rte_head->Q, &rte_elem->Q); + next_stop[0] = 0; + currtemsg += n; + } + + /* + * If this was the last fragment of the route, add it to the + * gpsbabel internal structs now. + */ + if (frag == mag_rte_head->nelems) { + queue *elem, *tmp; + route_head *rte_head; + + rte_head = route_head_alloc(); + route_add_head(rte_head); + + /* + * TODO: I suppose we have to fetch the waypoints to + * get the underlying data for each stop in the route. + */ + QUEUE_FOR_EACH(&mag_rte_head->Q, elem, tmp) { + static int lat; /* Dummy data */ + mag_rte_elem *re = (mag_rte_elem *) elem; + waypoint *waypt; + + waypt = xcalloc(sizeof *waypt, 1); + + /* TODO Populate rest of waypoint. */ + waypt->shortname = re->wpt_name; + waypt->position.latitude.degrees = ++lat; + + route_add_wpt(rte_head, waypt); + dequeue(&re->Q); + free(re); + } + } + return 0; +} const char * mag_find_descr_from_token(const char *token) -- 2.30.2